package com.lg.partition28;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/4/4 10:48
 */
public class P2746NetworkofSchools {

    private static final int N = 110, M = 10010;
    private static int[] h = new int[N], e = new int[M], ne = new int[M];
    private static int[] dfn = new int[N], low = new int[N], scc = new int[N], stk = new int[N], din = new int[N], dout = new int[N];
    private static boolean[] st = new boolean[N];
    private static int n, m, idx = 0, timestamp = 0, sccId = 0, top = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        Arrays.fill(h, -1);
        for (int i = 1; i <= n; i++) {
            String[] ss = reader.readLine().split(" ");
            for (int j = 0; j < ss.length; j++) {
                int v = Integer.parseInt(ss[j]);
                if (v == 0) break;
                add(i, v);
            }
        }
        resolve();
        writer.flush();
    }

    private static void resolve() throws IOException {
        for (int i = 1; i <= n; i++) {
            if (dfn[i] == 0) {
                tarjan(i);
            }
        }
        for (int u = 1; u <= n; u++) {
            for (int i = h[u]; i != -1; i = ne[i]) {
                int v = e[i];
                if (scc[u] == scc[v]) continue;
                din[scc[v]]++;
                dout[scc[u]]++;
            }
        }
        int p = 0, q = 0;
        for (int i = 1; i <= sccId; i++) {
            if (din[i] == 0) p++;
            if (dout[i] == 0) q++;
        }
        writer.write(p + "\n");
        //如果本来就是一个强连通图，不需要加任何的边
        if (sccId == 1) writer.write("0\n");
        else writer.write(Math.max(p, q) + "\n");
    }

    private static void tarjan(int u) {
        dfn[u] = low[u] = ++timestamp;
        stk[++top] = u;
        st[u] = true;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (dfn[v] == 0) {
                tarjan(v);
                low[u] = Math.min(low[u], low[v]);
            } else if (st[v]) {
                low[u] = Math.min(low[u], dfn[v]);
            }
        }
        if (dfn[u] == low[u]) {
            sccId++;
            int v = -1;
            do {
                v = stk[top--];
                st[v] = false;
                scc[v] = sccId;
            } while (u != v);
        }
    }

    private static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}
